home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Applications / ARTAbrot 1.0 / AB_Alert.c next >
Text File  |  1993-08-23  |  4KB  |  131 lines

  1. /*  AB_Alert                                         Handle this alert */
  2.  
  3. /* File name:  AB_Alert.c  */
  4. /* Function:  Handle this alert. */
  5. /* This is a NOTE alert, it is used to inform the user of some general information. */
  6. /* This alert is not used if there is a possibility of losing any data. */
  7. /* This alert is called when:   */
  8. /*     */
  9. /* The choices in this alert allow for:   */
  10. /*    
  11. History: 8/18/93 Original by George Warner
  12.    */
  13. #include <StdIO.h>
  14. #include <String.h>
  15. #include <Quickdraw.h>
  16. #include "ComUtil_ARTAbrot.h"    /* Common */
  17. #include "AB_Alert.h"    /* This file */
  18.  
  19.  
  20. #pragma segment AB_Alert
  21.  
  22. /********************************************************************
  23. *                                                                    *
  24. *    Function :    check_stop                                            *
  25. *                                                                    *
  26. *    Purpose:     Function to see if user typed Command-period.        *
  27. *                                                                    *
  28. *    Returns:     None.                                                *
  29. *                                                                    *
  30. *********************************************************************/
  31. int check_stop(void)
  32. {
  33. EventRecord  myEvent;
  34. char inchar;
  35.  
  36.     if (GetNextEvent(keyDownMask, &myEvent)) {
  37.         inchar = (char)(myEvent.message & charCodeMask);
  38.         if (((myEvent.modifiers & cmdKey) != 0) && (inchar == '.'))
  39.             return(true);
  40.         else return(false);
  41.     }
  42.     else return(false);
  43. }
  44.  
  45. /* ======================================================= */
  46. void I_A_Alert()
  47. {
  48.  
  49.  
  50. }
  51.  
  52. /* ======================================================= */
  53. void AB_Alert(char *err_description)
  54. {
  55. #define MAX_STRING 256
  56. char    tmp_string[MAX_STRING];
  57. GrafPtr    oldPort;
  58. WindowPtr        errorWindow;
  59. Rect             errorWBounds = { 40, 10, 140, 210 }; /* t,l,b,r */
  60. Rect    buttonRect;
  61. EventRecord  myEvent;
  62. int        hcenter, swidth;
  63. int rectwidth, rectheight;
  64. ControlHandle    Ctrl_OK;
  65. Point myPt;
  66. int GoodClick;
  67.  
  68.     /* Set the font. */
  69.     TextSize(12);
  70.     TextFont(systemFont);
  71.     
  72.     /* Get length of string. */
  73.     strncpy(tmp_string+1, err_description, MAX_STRING-1);
  74.     /* Make sure string ends in a NUL. */
  75.     tmp_string[MAX_STRING-1] = 0;
  76.     tmp_string[0] = strlen(err_description);
  77.     swidth = StringWidth((ConstStr255Param)tmp_string);
  78.     
  79.     /* Get window width and make sure it is enough. */
  80.     rectheight = errorWBounds.bottom - errorWBounds.top;
  81.     rectwidth = errorWBounds.right - errorWBounds.left;
  82.     if (rectwidth < swidth) {
  83.         rectwidth = swidth + 20;
  84.         errorWBounds.right = errorWBounds.left + rectwidth;
  85.     }
  86.     
  87.     GetPort(&oldPort); /* Get the current grafPort. */
  88.     errorWindow = NewWindow(0L, &errorWBounds, (ConstStr255Param)"\pError", true, noGrowDocProc, (WindowPtr)(-1L), true, 0L);
  89.     SetPort(errorWindow);
  90.     
  91. //    PenPat((ConstPatternParam)qd.black);
  92. //    BackPat((ConstPatternParam)qd.white);
  93.     
  94.     hcenter = rectwidth/2;
  95.  
  96.     MoveTo(hcenter - (swidth/2), 20);
  97.     DrawString((ConstStr255Param)tmp_string);
  98.  
  99.     buttonRect.right = rectwidth - 15;
  100.     buttonRect.bottom = rectheight - 15;
  101.     buttonRect.top = buttonRect.bottom - 22;
  102.     buttonRect.left = buttonRect.right - 64;
  103.     
  104.     Ctrl_OK = NewControl(errorWindow, &buttonRect, (ConstStr255Param)"\pOK", true, 1, 0, 0, 0, 1);
  105.     PenSize(3,3);
  106.     InsetRect(&buttonRect, -4, -4);       /* Draw outside the button by 1 pixel */
  107.     FrameRoundRect(&buttonRect, 16, 16); /* Draw the outline */
  108.  
  109.     GoodClick = false;
  110.     /* Wait for a mouse click in the window. */
  111.     
  112.     /* change cursor back to arrow */
  113.     InitCursor();
  114.     while (!GoodClick) {
  115.         /* Wait for a mouse click. */
  116.         while (!(GetNextEvent(mDownMask, &myEvent)));
  117.         myPt = myEvent.where;                                 /* Get mouse position */
  118.         GlobalToLocal(&myPt);                                /* Make it relative */
  119.         if (PtInRect(myPt,&buttonRect)) {
  120.             GoodClick = true;
  121.             HiliteControl(Ctrl_OK, 10);
  122.         }
  123.         else
  124.             SysBeep(1);
  125.     }
  126.     DisposeWindow(errorWindow);
  127.     SetPort(oldPort);                /* Restore old window. */
  128. }
  129.  
  130. /* ======================================================= */
  131.